<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('commerce_energy', function (Blueprint $table) {
            $table->comment('商户能耗');
            $table->bigIncrements('id')->comment('主键ID');
            $table->unsignedBigInteger('merchant_id')->comment('商户ID');
            $table->string('consumption_month', 7)->nullable()->comment('能耗月份（格式：2024-01）');
            $table->integer('cost_type')->comment('费用类型：1-水费，2-电费，3-气费，4-其他');
            $table->decimal('cost_usage', 12, 4)->default(0.0000)->comment('用量');
            $table->decimal('cost_price', 8, 2)->default(0.00)->comment('单价');
            $table->decimal('cost_meter_reading', 12, 4)->nullable()->comment('表读数');
            $table->decimal('total_amount', 12, 2)->default(0.00)->comment('总费用');
            $table->unsignedTinyInteger('payment_status')->default(1)->comment('缴费状态：1-未缴费，2-已缴费');
            $table->date('payment_date')->nullable()->comment('缴费日期');
            $table->unsignedTinyInteger('payment_method')->nullable()->comment('付款方式1-银行转账,2-微信支付,3-支付宝支付,4-现金,5-其他付款方式');
            $table->string('invoice_id', 128)->nullable()->comment('发票号');
            $table->string('meter_photos')->nullable()->comment('抄表照片');
            $table->string('bills_photos')->nullable()->comment('账单照片');
            $table->text('remark')->nullable()->comment('备注');
            $table->unique(['merchant_id', 'consumption_month'], 'uk_merchant_month');
            $table->index('consumption_month', 'idx_consumption_month');
            $table->index('payment_status', 'idx_payment_status');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('commerce_energy');
    }
};